package com.hzhr.iot.device.convertor.custom;

import com.hzhr.iot.device.convertor.DeviceInfoCardConvertor;
import com.hzhr.iot.device.entity.ext.*;
import com.hzhr.iot.device.model.regulatorDevice_infoCard.RegulatorDevice_InfoCardModel;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class DeviceInfoCardCustomConvertor extends DeviceInfoCardConvertor {

    @Override
    public RegulatorDevice_InfoCardModel ext2regulatorDevice_InfoCardModel(DeviceInfoCardEntityExt in) {
        RegulatorDevice_InfoCardModel result = super.ext2regulatorDevice_InfoCardModel(in);
        CollectDeviceEntityExt ext1 = in.getDeviceExt(); //deviceExt_code
        if (ext1 != null) {
            result.setDeviceCode(ext1.getCode());
            //deviceExt_deptId
            result.setDeptId(ext1.getDeptId());
            result.setManageUserId(ext1.getManageUserId()); //deviceExt_manageUserId
            //deviceExt_manageUserName
            result.setManageUserName(ext1.getManageUserName());
            //deviceExt_typeId
            result.setTypeId(ext1.getTypeId());
            //deviceExt_typeExt_des
            result.setTypeDes(ext1.getDes());
            //deviceExt_installAddress
            result.setInstallAddress(ext1.getInstallAddress());
            //deviceExt_usingDate
            result.setProdFactoryDes(ext1.getRegulatorDeviceProdFactory());

            Date date = ext1.getUsingDate(); //Date转long型
            if (date != null){
                result.setUsingDate(date.getTime());
            }

        }

        OptionsEntityExt ext2 = in.getSafetyDeviceExt();
        if (ext2 != null) {
            result.setSafetyDeviceDes(ext2.getDes());
        }

        return result;
    }

}

